package org.xtremeobjects.domain.model.java5;

import java.lang.reflect.Method;
import java.util.Collection;

import org.xtremeobjects.anotations.Hidden;

public abstract class AbstractMethodSpecification {

	public AbstractMethodSpecification() {
		super();
	}

	public abstract boolean isSatisfiedBy(Method method);

	protected boolean isHidden(Method method) {
		return method.isAnnotationPresent(Hidden.class);
	}

	protected boolean isSetter(Method method) {
		// check if is a setter
		if (method.getName().startsWith("set"))
			return true;
		return false;
	}
	
	
	protected boolean isGetter(Method method) {
		// check if is a getter
		if (!method.getName().startsWith("get"))
			return false;
	
		// check if has parameters
		if (method.getParameterTypes().length != 0)
			return false;
	
		return true;
	}

	protected boolean isArray(Method method) {
		return method.getReturnType().isArray();
	}

	protected boolean isClassGetter(Method method) {
		return method.getName().equals("getClass");
	}

	protected boolean isCollection(Method method) {
		return Collection.class.isAssignableFrom(method.getReturnType());
	}

}